/**
 * 
 */
package com.nervytech.tutorcruise.db.dao.mysql.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;

import com.nervytech.tutorcruise.db.dao.interfaces.ICategoryDAO;

/**
 * @author ADMIN
 * 
 */
@Repository("categoryDAO")
public class CategoryDAO extends JdbcDaoSupport implements ICategoryDAO {

	@Autowired
	CategoryDAO(DataSource dataSource) {
		setDataSource(dataSource);
	}

	@Override
	public String getCategoryName(int categoryId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getCategoryId(String categoryName) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Map<Integer, String> getCategoryMap() {

		final Map<Integer, String> catsMap = new LinkedHashMap<Integer, String>();

		String selectCatsQuery = "SELECT * FROM CATEGORY";

		logger.debug("Select user Query : " + selectCatsQuery);

		getJdbcTemplate().query(selectCatsQuery,
				new ResultSetExtractor<Object>() {

					@Override
					public Object extractData(ResultSet rs)
							throws SQLException, DataAccessException {

						while (rs.next()) {
							catsMap.put(rs.getInt("category_id"),
									rs.getString("name"));
						}
						return null;
					}
				});

		return catsMap;

	}

}
